package test;


import io.github.biezhi.wechat.WeChatBot;
import io.github.biezhi.wechat.api.annotation.Bind;
import io.github.biezhi.wechat.api.constant.Config;
import io.github.biezhi.wechat.api.enums.AccountType;
import io.github.biezhi.wechat.api.enums.MsgType;
import io.github.biezhi.wechat.api.model.WeChatMessage;
import io.github.biezhi.wechat.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import test.util.DuiLieUtils;
import test.util.TuLingUtil;
@Slf4j
public class HelloBot extends WeChatBot {

    public HelloBot(Config config) {
        super(config);
    }
    /**
     * 分享消息
     * @param message
     */
    @Bind(msgType = MsgType.SHARE)
    public void handleText(WeChatMessage message) {
        if (StringUtils.isNotEmpty(message.getName())) {
           log.info("接收到 [{}] 的消息: {}", message.getName(),message.getText());
           this.sendMsg(DuiLieUtils.getDuiLieUtils().get().toString(),  message.getRaw().getFileName()+"请点击查看"+message.getText());
        }
    }
    
    /**
     * friend
     * @param message
     */
    @Bind(accountType = AccountType.TYPE_FRIEND)
    public void friendMessage(WeChatMessage message) {
        if(StringUtils.isNotEmpty(message.getName()) ){
        	log.info("接收到 [{}] 的消息: {}", message.getName(),message.getText());
        	if(message.getText().indexOf("m.tb.cn")>-1) {//淘宝优惠
        	  DuiLieUtils.getDuiLieUtils().add(message.getFromUserName());
         	  this.sendMsg(this.api().getAccountByName("淘淘惠").getUserName(),  message.getText());
            }else {
            	this.sendMsg(message.getFromUserName(), TuLingUtil.getTuling().getMessage(message.getText()));
            }
        }
    }
    /**
     * group
     * @param message
     */
    @Bind(accountType = AccountType.TYPE_GROUP)
    public void groupMessage(WeChatMessage message) {
        if(StringUtils.isNotEmpty(message.getName()) ){
        	log.info("接收到 [{}] 的消息: {}", message.getName(),message.getText());
        	if(message.getText().indexOf("m.tb.cn")>-1) {//淘宝优惠
          	  DuiLieUtils.getDuiLieUtils().add(message.getFromUserName());
           	  this.sendMsg(this.api().getAccountByName("淘淘惠").getUserName(),  message.getText());
            }else {
        	  this.sendMsg(message.getFromUserName(), TuLingUtil.getTuling().getMessage(message.getText()) );
            }
        }
    }
    
    /**
       *   添加好友
     * @param message
     */
    @Bind(msgType = MsgType.ADD_FRIEND)
    public void addFriend(WeChatMessage message) {
        log.info("收到好友验证消息: {}", message.getText());
        if (message.getText().contains("java")) {
            this.api().verify(message.getRaw().getRecommend());
        }
        this.api().verify(message.getRaw().getRecommend());
    }
    
    public static void main(String[] args) {
        new HelloBot(Config.me().autoLogin(true).showTerminal(true)).start();
    }

}
